﻿using SuperMap.Data;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace Ycjw.PipeLine.Map.Tools.Conditions.JJAnalysts
{
    public partial class TextureForm : Sunny.UI.UIForm
    {
        private GeoStyle3D m_geoStyle3D;

        public GeoStyle3D GeoStyle3D
        {
            get
            {
                return this.m_geoStyle3D;
            }
        }

        public TextureForm()
        {
            InitializeComponent();
            InitializeComponentResources();
            InitializeControls();
        }

        private void InitializeComponentResources()
        {
            if (SuperMap.Data.Environment.CurrentCulture == "zh-CN")
            {
                this.m_labelDepth.Text = "地下深度:";
                this.m_labelBottomRepeatMode.Text = "重复模式:";
                this.m_labelBottomTextureFile.Text = "贴图来源:";
                this.m_buttonConfirm.Text = "确定";
                this.m_labelBottomTillingU.Text = "横向重复:";
                this.m_labelSideTillingV.Text = "纵向重复:";
                this.m_labelSideTillingU.Text = "横向重复:";
                this.m_labelSideRepeatMode.Text = "重复模式:";
                this.m_buttonCancel.Text = "取消";
                this.m_labelSideTextureFile.Text = "贴图来源:";
                this.m_groupBoxBottomTexture.Text = "底面贴图设置";
                this.m_labelBottomTillingV.Text = "纵向重复:";
                this.m_groupBoxSideTexture.Text = "侧面贴图设置";
                this.Text = "开挖区域填充设置";
            }
        }

        private void InitializeControls()
        {

            this.m_textBoxBottomTextureFile.Text = Path.GetFullPath(Commons.Paths.ApplicationResourcesDir + "\\Top.png");
            this.m_textBoxSideTextureFile.Text = Path.GetFullPath(Commons.Paths.ApplicationResourcesDir +  "\\Side.JPG");

            this.m_comboBoxSideRepeatMode.Items.Clear();
            this.m_comboBoxBottomRepeatMode.Items.Clear();

            if (SuperMap.Data.Environment.CurrentCulture == "zh-CN")
            {
                this.m_comboBoxSideRepeatMode.Items.Add("重复次数");
                this.m_comboBoxSideRepeatMode.Items.Add("实际大小");

                this.m_comboBoxBottomRepeatMode.Items.Add("重复次数");
                this.m_comboBoxBottomRepeatMode.Items.Add("实际大小");
            }
            else
            {
                this.m_comboBoxSideRepeatMode.Items.Add("Repeat Number");
                this.m_comboBoxSideRepeatMode.Items.Add("Actual Size");

                this.m_comboBoxBottomRepeatMode.Items.Add("Repeat Number");
                this.m_comboBoxBottomRepeatMode.Items.Add("Actual Size");
            }
            this.m_comboBoxSideRepeatMode.SelectedIndex = 0;
            this.m_comboBoxBottomRepeatMode.SelectedIndex = 0;
        }

        private void TextureForm_Load(object sender, EventArgs e)
        {
            InitializeControls();
        }
        private void m_buttonSideTextureFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dialog = new OpenFileDialog();
                if (SuperMap.Data.Environment.CurrentCulture == "zh-CN")
                {
                    dialog.Filter = "所有被支持文件(*.PNG;*.jpg;*.bmp)|*.png;*.jpg;*.bmp|PNG文件(*.PNG)|*.png|JPG文件(*.jpg)|*.jpg|位图文件(*.bmp)|*.bmp";
                }
                else
                {
                    dialog.Filter = "All supported files(*.PNG;*.jpg;*.bmp)|*.png;*.jpg;*.bmp|PNG File(*.PNG)|*.png|JPG File(*.jpg)|*.jpg|bmp File(*.bmp)|*.bmp";
                }
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    m_textBoxSideTextureFile.Text = dialog.FileName;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }

        private void m_buttonBottomTextureFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dialog = new OpenFileDialog();
                if (SuperMap.Data.Environment.CurrentCulture == "zh-CN")
                {
                    dialog.Filter = "所有被支持文件(*.PNG;*.jpg;*.bmp)|*.png;*.jpg;*.bmp|PNG文件(*.PNG)|*.png|JPG文件(*.jpg)|*.jpg|位图文件(*.bmp)|*.bmp";
                }
                else
                {
                    dialog.Filter = "All supported files(*.PNG;*.jpg;*.bmp)|*.png;*.jpg;*.bmp|PNG File(*.PNG)|*.png|JPG File(*.jpg)|*.jpg|bmp File(*.bmp)|*.bmp";
                }
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    m_textBoxBottomTextureFile.Text = dialog.FileName;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }


        private void m_textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != '\b' && !Char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
                m_buttonConfirm.Enabled = true;
            }
        }


        private void m_buttonConfirm_Click(object sender, EventArgs e)
        {
            this.m_geoStyle3D = new GeoStyle3D();

            this.m_geoStyle3D.BottomAltitude = 0;
            this.m_geoStyle3D.ExtendedHeight = (-1) * Convert.ToDouble(this.m_textBoxDepth.Text);
            this.m_geoStyle3D.SideTextureFiles = new String[] { this.m_textBoxSideTextureFile.Text };
            this.m_geoStyle3D.TilingU = Convert.ToDouble(this.m_textBoxSideTillingU.Text);
            this.m_geoStyle3D.TilingV = Convert.ToDouble(this.m_textBoxSideTillingV.Text.ToString());
            this.m_geoStyle3D.TopTextureFile = this.m_textBoxBottomTextureFile.Text;
            this.m_geoStyle3D.TopTilingU = Convert.ToDouble(this.m_textBoxBottomTillingU.Text.ToString());
            this.m_geoStyle3D.TopTilingV = Convert.ToDouble(this.m_textBoxBottomTillingV.Text.ToString());

            if (this.m_comboBoxSideRepeatMode.SelectedIndex == 0)
            {
                this.m_geoStyle3D.TextureRepeatMode = TextureRepeatMode.RepeatTimes;
            }
            else if (this.m_comboBoxSideRepeatMode.SelectedIndex == 1)
            {
                this.m_geoStyle3D.TextureRepeatMode = TextureRepeatMode.RealSize;
            }

            if (this.m_comboBoxBottomRepeatMode.SelectedIndex == 0)
            {
                this.m_geoStyle3D.TopTextureRepeatMode = TextureRepeatMode.RepeatTimes;
            }
            else if (this.m_comboBoxBottomRepeatMode.SelectedIndex == 1)
            {
                this.m_geoStyle3D.TopTextureRepeatMode = TextureRepeatMode.RealSize;
            }

            this.Close();
        }

        private void m_buttonCancel_Click(object sender, EventArgs e)
        {
            m_geoStyle3D = null;
            this.Close();
        }
    }
}


